home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 10615 / 10615.xpi / chrome / firedownload.jar / content / downloads-overlay.js next >
Text File  |  2009-06-17  |  3KB  |  87 lines

  1. //@line 2 "z:\Development\moztrunk\src\extensions\firedownload\chrome\content\downloads-overlay.js"
  2.  
  3. var FireDownloadManager = {
  4.   defaultPauseFunction : null,
  5.   defaultResumeFunction : null,
  6.   defaultCancelFunction : null,
  7.   defaultRetryFunction : null,
  8.   defaultCreateDownloadItem : null,
  9.   useFieryBar : true,
  10.  
  11.   init : function fdm_init() {
  12. //@line 18 "z:\Development\moztrunk\src\extensions\firedownload\chrome\content\downloads-overlay.js"
  13.   
  14.     FireDownloadManager.defaultPauseFunction = window.pauseDownload;
  15.     window.pauseDownload = function(aDownload) {
  16.       var download = FireDownloadManager.getFireDownload(aDownload);
  17.       if (download) {
  18.         download.pauseDownload();
  19.         aDownload.setAttribute("state", Ci.nsIDownloadManager.DOWNLOAD_PAUSED);
  20.       }
  21.       else {
  22.         FireDownloadManager.defaultPauseFunction(aDownload);
  23.       }
  24.     }
  25.  
  26.     FireDownloadManager.defaultResumeFunction = window.resumeDownload;
  27.     window.resumeDownload = function(aDownload) {
  28.       var download = FireDownloadManager.getFireDownload(aDownload);
  29.       if (download) {
  30.         download.resumeDownload();
  31.         aDownload.setAttribute("state", Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING);
  32.       }
  33.       else {
  34.         FireDownloadManager.defaultResumeFunction(aDownload);
  35.       }
  36.     }
  37.  
  38.     FireDownloadManager.defaultCancelFunction = window.cancelDownload;
  39.     window.cancelDownload = function(aDownload) {
  40.       var download = FireDownloadManager.getFireDownload(aDownload);
  41.       if (download) {
  42.         aDownload.setAttribute("firedownload", download.URL);
  43.       }
  44.       FireDownloadManager.defaultCancelFunction(aDownload);
  45.     }
  46.  
  47.     FireDownloadManager.defaultRetryFunction = window.retryDownload;
  48.     window.retryDownload = function(aDownload) {
  49.       var url = aDownload.getAttribute("firedownload");
  50.       if (url && url != "") {
  51.         removeFromView(aDownload);
  52.         download = Cc["@mozilla.org/firedownload;1"].createInstance(Ci.nsIFireDownload);
  53.         download.startDownload(url, "");
  54.       }
  55.       else {
  56.         FireDownloadManager.defaultRetryFunction(aDownload);
  57.       }
  58.     }
  59.     
  60.     FireDownloadManager.defaultCreateDownloadItem = window.createDownloadItem;
  61.     window.createDownloadItem = function(aAttrs) {
  62.       var dl = FireDownloadManager.defaultCreateDownloadItem(aAttrs);
  63.       if (dl) {
  64.         var download = FireDownloadManager.getFireDownload(dl);
  65.         if (download && FireDownloadManager.useFieryBar) {
  66.           dl.setAttribute("firedownload", "true");
  67.         }
  68.       }
  69.       return dl;
  70.     }
  71.   },
  72.  
  73.   getFireDownload : function fdm_getFireDownload(aDownload) {
  74.     var dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
  75.     var id = aDownload.getAttribute("dlid");
  76.     var download = dm.getDownload(id);
  77.     if (download.cancelable instanceof Ci.nsIFireDownload) {
  78.       return download.cancelable.QueryInterface(Ci.nsIFireDownload);
  79.     }
  80.     else {
  81.       return null;
  82.     }
  83.   } 
  84. };
  85.  
  86. window.addEventListener("load", function(e) { FireDownloadManager.init(); }, false);
  87.